package com.lovo.service.impl;

import com.lovo.dao.StudentDAO;
import com.lovo.model.StudentDO;
import com.lovo.service.StudentService;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;

/**
 * @title
 * @author: luo
 * @date: 2020/11/18 20:27
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private  StudentDAO studentDAO;

    @Override
    public List<StudentDO> findAll() {
        return studentDAO.findAll();
    }

    @Override
    public StudentDO findById(Integer studentId) {
        return studentDAO.findById(studentId).get();
    }

    @Override
    public void save(StudentDO studentDO) {
        studentDAO.save(studentDO);
    }

    @Override
    public void delete(StudentDO studentDO) {
        studentDAO.delete(studentDO);
    }
    @Override
    public void update(StudentDO studentDO){
        studentDAO.save(studentDO);
    }

//    @Override
//    public List findByDynamic(String type, String value) {
//
//        return studentDAO.findAll(new Specification<StudentDO>() {
//            @Override
//            public Predicate toPredicate(Root<StudentDO> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
//                List<Predicate>predicateList = new ArrayList<>();
//                predicateList.add(criteriaBuilder.equal(root.get(type),value));
////                predicateList.add(criteriaBuilder.like(root.get("name"),"%罗%"));
//                return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
//            }
//        });
//
//
//    }
}
